<template>
  <!-- <iframe
    v-if="$route.query.src"
    :src="$route.query.src"
    class="iframe"
    ref="iframe"
    v-loading.fullscreen.lock="screenLoading"
  ></iframe>-->
  <div v-loading="screenLoading">
    <iframe ref="iframe" :src="src" class="iframe" />
  </div>
</template>

<script>
export default {
  name: 'Myiframe',
  components: {
  },
  // props: ['routerPath'],
  data() {
    return {
      screenLoading: false,
      urlPath: this.getUrlPath()
    }
  },
  computed: {
    src: function() {
      const path = window.location.href.split('iframe/')[1]
      if (path === 'baidu') {
        return 'http://www.baidu.com'
      } else {
        return this.getUrlPath()
      }
    }
  },
  watch: {
    routerPath: function(val) {
      this.urlPath = this.getUrlPath()
    }
  },
  created() {
    this.screenLoading = true
  },
  mounted() {
    this.iframeInit()
    // window.onresize = () => {
    //   // 防止iframe关闭后，还调整窗口报错
    //   if (this.$refs.iframe) {
    //     this.iframeInit()
    //   }
    // }
  },
  methods: {
    iframeInit() {
      const iframe = this.$refs.iframe
      const clientHeight = document.documentElement.clientHeight - 90
      iframe.style.height = `${clientHeight}px`
      if (iframe.attachEvent) {
        iframe.attachEvent('onload', () => {
          this.screenLoading = false
        })
      } else {
        iframe.onload = () => {
          this.screenLoading = false
        }
      }
    },
    getUrlPath: function() {
      let url = window.location.href
      url = url.replace('/iframe', '')
      return url
    }
  }
}
</script>

<style>
.iframe {
  width: 100%;
  height: 100%;
  border: 0;
  overflow: hidden;
  box-sizing: border-box;
}
</style>
